<%@ page language="java" pageEncoding="UTF-8"%>
<%@ include file="../../taglib.jsp"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<base href="<%=basePath%>" />
<%@ include file="/webmodules/console/css.jsp"%>
<%@ include file="/webmodules/console/js.jsp"%>
<script type="text/javascript" src="plugins/${KindeditorRelease}/kindeditor-min.js"></script>
</head>
<body>
	<div style="width: 100%; height: 100%; overflow: auto;">
		<form id="myform" method="post">
			<input type="hidden" id="path" name="path" value="${param.path }"> <input type="hidden" id="action" name="action" value="${param.action }">
			<table width="100%" border="0">
				<tr>
					<td width="15%">文件名</td>
					<td width="85%"><input type="text" id="filename" name="filename" width="200px" value="${filename }" /></td>
				</tr>
				<tr>
					<td>文件内容</td>
					<td><textarea id="filecontent" name="filecontent" style="width: 100%; height: 300px">${filecontent }</textarea>
				</tr>
				<tr>
					<td></td>
					<td><textarea id="filecontent2" name="filecontent2" style="width: 100%; height: 300px">${filecontent }</textarea>
				</tr>
			</table>
		</form>
		<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0" class="dialog_button_bar">
			<tbody>
				<tr>
					<td>
						<div align="right">
							<a href="javascript:void(0);" class="easyui-linkbutton" iconCls="icon-save" onclick="save('save');">保存</a> <a href="javascript:void(0);" class="easyui-linkbutton" iconCls="icon-back"
								onclick="save('saveclose');">保存并关闭</a> <a href="javascript:void(0);" " class="easyui-linkbutton" iconCls="icon-cancel" onclick="top.closeWindow('editFile');">关闭</a>
						</div>
					</td>
				</tr>
			</tbody>
		</table>
	</div>
</body>
<script type="text/javascript">
	var filecontent;
	var savemode = 'save_close';
	$(function() {
		$('#myform').form({
			url : 'dragon/modules/file/action/FileHandler/saveFile.ejw',
			onSubmit : function() {
				return $(this).form('validate');
			},
			success : function(data) {
				try {
					data = eval('(' + data + ')');
				} catch (e) {
					top.showErrorMsg("出错了", data);
					return;
				}
				if (data.MESSAGE_ERROR != undefined && data.MESSAGE_ERROR != '') {
					top.showMsg("错误", data.MESSAGE_ERROR, true, 'error');
				} else if (data.MESSAGE_WARNING != undefined && data.MESSAGE_WARNING != '') {
					top.showMsg("警告", data.MESSAGE_WARNING, true, 'warning');
				} else {
					if (data.MESSAGE_INFO != undefined && data.MESSAGE_INFO != '') {
						top.showMsg("", data.MESSAGE_INFO, false);
					} else {
						top.showMsg("", ($('#action').val() == 'create' ? '创建' : '修改') + "文件成功！", false);
					}
					$('#action').val('modify');/*保存成功后将action置为modify*/
					top.$('#tabsconetnt').tabs('getSelected').find('iframe')[0].contentWindow.$('#mydatagrid').datagrid('reload');
					if (savemode == 'saveclose') {
						top.closeWindow('editFile');
					}
				}
			}
		});
		KindEditor.basePath = 'plugins/${KindeditorRelease}/';
		filecontent = KindEditor.create('#filecontent', {
			minHeight : 300,
			items : ['template', 'fullscreen' ],
			noDisableItems : ['template', 'fullscreen' ],
			designMode : false
		});
		KindEditor.create('#filecontent2', {
			minHeight : 300,
			designMode : true
		});
	});
	function save(p_savemode) {
		savemode = p_savemode;
		var fileName = $('#filename').val().trim();
		if (fileName.length <= 0) {
			top.showMsg('错误', '请输入文件名！', true, 'error');
			$('#filename').focus();
			return;
		}
		filecontent.sync();
		$('#myform').submit();
	}
</script>
</html>
